<template>
    <div class="board">
        <!-- 顶部navbar -->
        <van-nav-bar title="宠物寄养" />
        <!-- 商家卡片 -->
        <BoardCard></BoardCard>
    </div>
</template>

<script>
import BoardCard from '../components/BoardCard.vue';
export default {
    props: {

    },
    components: {
        BoardCard
    },
    data() {
        return {

        }
    },
    methods: {

    },
    //在页面离开时记录滚动位置,这里的this.scrollTop可以保存在vuex的state或者浏览器本地
    beforeRouteLeave(to, from, next) {
        this.scrollTop = document.documentElement.scrollTop || document.body.scrollTop
        sessionStorage.setItem("scroll", this.scrollTop)
        next()
    },

    //进入该页面时，用之前保存的滚动位置赋值
    beforeRouteEnter(to, from, next) {
        next(vm => {
            // document.body.scrollTop = vm.scrollTop
            // console.log(sessionStorage.getItem("scroll"));
            // this.$nextTick()
            document.body.scrollTop = sessionStorage.getItem("scroll")
        })
    }
}
</script>

<style scoped></style>
